﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace ZJGIS.Resources
{
    /// <summary>
    /// 资源操作类
    /// </summary>
    public class ResourcesHelper
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        protected ResourcesHelper()
        {

        }

        /// <summary>
        /// 根据文件名得到图标对象
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Icon GetIcon(string name)
        {
            Stream stream = LoadStream(name);
            if (stream == null) return null;
            return new Icon(stream);
        }

        /// <summary>
        /// 获取图片
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Image GetImage(string name)
        {
            Stream stream = LoadStream(name);
            if (stream == null) return null;
            return new Bitmap(stream);
        }

        /// <summary>
        /// 根据文件名得到指针对象
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Cursor GetCursor(string name)
        {
            Stream stream = LoadStream(name);
            if (stream == null)return null;
            return new Cursor(stream);
        }

        /// <summary>
        /// 得到文件的字节视图
        /// </summary>
        private static Stream LoadStream(string filename)
        {
            Assembly assembly = Assembly.GetAssembly(typeof(ResourcesHelper));
            string name = String.Format("ZJGIS.Resources.{0}", filename);
            return assembly.GetManifestResourceStream(name);
        }
    }


}
